// 毫秒
export class CDTimer{
    private lastUseTimestamp:number = 0
    private cdTime:number

    constructor(time:number){
        this.cdTime = time
    }

    getCD():number{
        return this.cdTime
    }

    getLeftTime(){
        return this.lastUseTimestamp + this.cdTime - Date.now()
    }

    canUse():boolean{
        let currentTime = Date.now()
        if((this.lastUseTimestamp + this.cdTime) > currentTime) return false
        this.lastUseTimestamp = currentTime
        return true
    }
}